
package me.zhengjie.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.rest.vo.Gps2VO;
import me.zhengjie.service.AppDakaService;
import me.zhengjie.service.dto.AppDakaQueryCriteria;
import me.zhengjie.utils.DateUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "考勤记录管理")
@RequestMapping("/api/daka")
public class ApiDakaController {

    private final AppDakaService appDakaService;


    @GetMapping(value = "/info")
    @ApiOperation("打卡首页")
    public Map info(){

        return appDakaService.info();
    }

    @PostMapping(value = "/act")
    @ApiOperation("打卡操作")
    public Map dakaAct(@RequestBody Gps2VO gpsVO){
        return appDakaService.dakaAct(gpsVO);
    }


    @GetMapping("/list")
    @Log("查询考勤记录")
    @ApiOperation("查询考勤记录")
    public ResponseEntity<Object> queryAppDaka(@RequestParam(defaultValue = "") String date,
                                               AppDakaQueryCriteria criteria,
                                               @PageableDefault(sort = {"dkId"}, direction = Sort.Direction.DESC) Pageable pageable){
        if(!date.equals("")){
            criteria.setCreateTime(DateUtils.getMonthBetween(date));
        }
        return new ResponseEntity<>(appDakaService.queryAllApi(criteria,pageable),HttpStatus.OK);
    }




}